#include <QtCore/QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdio.h>
#include <iostream>

int main(int argc, char *argv[])
{
    /******************************************** ABRINDO E GIRANDO UMA IMAGEM ********************************************************/
    cv::Mat image;
    image = cv::imread("/home/AndreLuiz/QtCreator/ContagemDeCarros/sala.jpg");
    std::cout << "\n altura: " << image.size().height << "\n largura: " << image.size().width;
    cv::namedWindow("Original Image");
    cv::imshow("Original Image", image);

    cv::Mat flipH;
    cv::flip(image,flipH,1);
    cv::namedWindow("Flip Image horizontal");
    cv::imshow("Flip Image horizontal", flipH);

    cv::Mat flipR;
    cv::flip(image,flipR, 0);
    cv::namedWindow("Flip Image vertical");
    cv::imshow("Flip Image vertical", flipR);

   cv::waitKey(1);
/*******************************************************************************************************************************************/

/************************************************ ABRINDO UM VIDEO E MOSTRA FRAME A FRAME **************************************************/

    // Open the video file
    cv::VideoCapture capture("/home/AndreLuiz/QtCreator/ContagemDeCarros/carros.flv");

    // check if video successfully opened
    if (!capture.isOpened())
        return 1;

    // Get the frame rate
    double rate= capture.get(CV_CAP_PROP_FPS);
    bool stop(false);
    cv::Mat frame; // current video frame
    cv::namedWindow("Extracted Frame");

    // Delay between each frame in ms
    // corresponds to video frame rate
    //int delay= 1000/rate;

    // for all frames in video
    while (!stop) {
        // read next frame if any
        if (!capture.read(frame))
            break;

        cv::imshow("Extracted Frame",frame);

        // introduce a delay
        // or press key to stop
        if (cv::waitKey(1)>=1)  /* ------------------------------------>>> GAMBIARRA PRA O VÍDEO RODA CONTÍNUO <<< --------------------------*/
            stop= true;
    }
        // Close the video file.
        // Not required since called by destructor
    capture.release();



    return 1;
}
/*******************************************************************************************************************************************/
